# 设置变量
# 包目录
$packFolder = (Get-Item -Path "./" -Verbose).FullName
$rootFolder = Join-Path $packFolder "/"
# 设置统一版本
$version = "1.0.2"

# 解决方案下的子项目目录
$projects = @(
    "Nexus.Infrastructure"
)

# 生成nuget packages
foreach($project in $projects) {
    
    $projectFolder = Join-Path $rootFolder $project


    # Create nuget pack
    Set-Location $projectFolder


    & dotnet clean  $project.csproj -c Release
    & dotnet restore $project.csproj -c Release
    & dotnet build $project.csproj -c Release /p:Version=$version
    
    # 创建nuget包
    & dotnet pack $project.csproj -c debug
      
    & dotnet nuget setapikey 102e201c-2d75-3a37-a2da-c584b7c04c43 -source http://localhost:8081/repository/nuget-hosted/

    # 推送nuget包
    $projectName = $project.Substring($project.LastIndexOf("/") + 1)


    $packagePath = Join-Path $projectFolder "bin/Release"
	

    Set-Location $packagePath
    & dotnet nuget push ($projectName + "." + $version + ".nupkg") -s http://127.0.0.1:8081/repository/nuget-hosted/ --api-key "102e201c-2d75-3a37-a2da-c584b7c04c43"
}
# 返回
Set-Location $packFolder